import { defineStore } from "pinia";
import { reqHospitalDetail, reqHospitalDeparment } from '@/api/hospital/index'
import type { HospitalDetailState, HospitalDetailResponseData, HospitalDetail, DeparmentResponseData, DeparmentArr } from '@/api/hospital/type'

const useDetailStore = defineStore('Detail', {
  state: (): HospitalDetailState => {
    return {
      //医院详情数据
      hospitalInfo: ({} as HospitalDetail),
      //医院科室数据
      deparmentArr: ([] as DeparmentArr)
    }
  },
  actions: {
    //获取医院详情数据
    async getHospital(hoscode: string) {
      let result: HospitalDetailResponseData = await reqHospitalDetail(hoscode)
      if (result.code == 200) {
        this.hospitalInfo = result.data
      }
    },
    //获取医院科室数据
    async getDeparment(hoscode: string) {
      let result: DeparmentResponseData = await reqHospitalDeparment(hoscode)
      if (result.code == 200) {
        this.deparmentArr = result.data
      }
    }
  },
  getters: {

  }
})

export default useDetailStore;